<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>面试题</title>
</head>
<body>
    
<script type="text/javascript">
    // 代码片段一
    var name = 'the window'
    var object = {
        name:'my Object',
        getNameFunc: function(){
            return function(){
                return this.name;
            }
        }
    }
    alert(object.getNameFunc()()) // ?  the window 注：无闭包
    /*
        没听懂老师怎么讲的，自己理解为：
            object.getNameFunc() = function(){ return this.name }
            object.getNameFunc()是内部的函数，而函数加() 相当于全局调用，this指向window
            object.getNameFunc()() = function()()
    */


    // 代码片段二
    var name2 = 'the window'
    var object2 = {
        name2 : 'my Object',
        getNameFunc : function(){
            var that = this
            return function(){
                return that.name2
            }
        }
    }
    alert(object2.getNameFunc()())  // my Object 注：有闭包
    /*
        object2.getNameFunc() 依旧等于 function()
            但此时没使用this，所以未指向window，
            而that是getNameF 定义的，所以指向object2中的name 
    */
</script>
</body>
</html>